package com.moyq5.permit.center.web;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * Json转换配置
 * @author Moyq5
 * @date 2018年8月3日
 */
@Configuration
public class JacksonConfiguration {

	@Bean
	public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
		Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
		
		builder.featuresToEnable(SerializationFeature.WRITE_ENUMS_USING_INDEX);
		builder.featuresToEnable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL);
		
		builder.featuresToDisable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
		builder.featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
		builder.featuresToDisable(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS);
		
		builder.serializationInclusion(Include.NON_NULL);
		builder.serializationInclusion(Include.NON_EMPTY);
		
		return builder;
	}
	
}
